H3 Grid and Food Security#
This notebook showcases how the proposed H3 grids (level 6) relate to sub-national areas with accute food insecurity phases (IPC).
Here, we compare the latest data avialble for Kenya from FEWS NET and FAO/IPC, and propose an approach to merge the scores into the standardized grid.
Show code cell source
import sys, os
from os.path import join, expanduser, basename
import geopandas as gpd
sys.path.append(join("X:", 'Repos', 'pacific-observatory', 'scripts', 'python'))
import folium as flm
from grid_utils import *
from matplotlib.colors import ListedColormap
import ee
ee.Initialize()
from geemap.conversion import *
from geemap.foliumap import Map
from geemap import colormaps
DATA_DIR = join("X:", 'data', 'CRW')
target_path = os.path.join(DATA_DIR, 'Shapefile', 'FEWS_Admin_LZ_v3_simplified.shp')
adm0_path = os.path.join(DATA_DIR, 'Shapefile', 'FEWS_Admin_LZ_adm0.shp')
aoi = gpd.read_file(target_path)
aoi = aoi.to_crs('EPSG:4326')
countries = ['Kenya']
# # countries = ['Somalia', 'South Sudan', 'Haiti', 'Kenya', 'Afghanistan', 'Democratic Republic of the Congo']
aoi = aoi.loc[aoi.ADMIN0.isin(countries)].copy()
adm0 = gpd.read_file(adm0_path)
adm0 = adm0.loc[adm0.ADM0_NAME.isin(countries)].copy()
1. Latest IPC data from FEWS NET, Februrary 2023#
The FEWS NET data is provided at the intersection of sub-national areas and livelihood zones.
Show code cell source
fews_latest = join(DATA_DIR, 'notebook', 'true', '2023', 'may5', 'FEWS February 2023 Update TrueBoundaries_05-05-23.csv')
fews_df = pd.read_csv(fews_latest)
fews_df = fews_df.loc[fews_df.year_month=="2023_02"].copy()
fews_df = fews_df.loc[fews_df.country==countries[0]].copy()
aoi_df = aoi.merge(fews_df[['admin_code', 'fews_ipc_adjusted']], on="admin_code", how="left")
green = (220/255, 240/255, 220/255)
yellow = (250/255, 230/255, 30/255)
orange = (230/255, 120/255, 0/255)
red = (200/255, 0/255, 0/255)
darkred = (100/255, 0/255, 0/255)
cmap = ListedColormap([green, yellow, orange, red, darkred])
m = aoi_df.explore(
column='fews_ipc_adjusted',
tooltip= ["admin_name", "admin_code", "ADMIN0", "fews_ipc_adjusted"],
name="FEWS Admin LZ",
cmap = cmap,
categorical = True,
categories = [1,2,3,4,5],
legend_kwds=dict(caption='Integrated Phase Classification'),
legend=True
)
flm.LayerControl().add_to(m)
m
Make this Notebook Trusted to load map: File -> Trust Notebook
2. Map IPC data to H3 grid (level 6)#
We merge the IPC phases to the H3 grid using a spatial overlay, assigning phases based on largest overlap.
Show code cell source
adm0 = adm0.explode(index_parts=False)
h3_df = gdf_to_hex_df(adm0, 6, overfill=False)
h3_df.drop_duplicates('hex_id', inplace=True)
h3_gdf = h3list_to_gdf(h3_df)
h3_gdf_join = gpd.overlay(h3_gdf, aoi_df[['admin_code', 'admin_name', 'fews_ipc_adjusted', 'geometry']], how='intersection')
h3_gdf_join = h3_gdf_join.to_crs('EPSG:3857')
h3_gdf_join.loc[:, 'area'] = h3_gdf_join.area
h3_gdf_join.sort_values(by='area', inplace=True, ascending=False)
h3_gdf_join.drop_duplicates(subset='hex_id', keep='first', inplace=True)
h3_gdf_merge = h3_gdf.merge(h3_gdf_join[['hex_id', 'admin_code', 'admin_name', 'fews_ipc_adjusted']], on="hex_id", validate='1:1')
m = aoi_df.explore(
column='fews_ipc_adjusted',
tooltip= ["admin_name", "admin_code", "ADMIN0", "fews_ipc_adjusted"],
name="FEWS Admin LZ",
cmap = cmap,
categorical = True,
categories = [1,2,3,4,5],
legend_kwds=dict(caption='Integrated Phase Classification'),
legend=True
)
h3_gdf_merge.explore(
m = m,
column='fews_ipc_adjusted',
tooltip= ["admin_name", "admin_code", "fews_ipc_adjusted"],
name="H3 Grid Level 6",
cmap = cmap,
categorical = True,
categories = [1,2,3,4,5],
legend=False
)
flm.LayerControl().add_to(m)
m
Input polygon is too small to be filled in with hexagon of resolution: 6
Attempting to fit a hex of resolution: 7...
A hex of resolution: 7 fits the input polygon
Finding it's parent in resolution: 6
Make this Notebook Trusted to load map: File -> Trust Notebook